﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;


namespace SES.CMS
{
    public partial class Article : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MasterPage mt = this.Master as MasterPage;
            Control uc = mt.FindControl("ucHomeSlide1") as Control;
            uc.Visible = false;
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                int ArtID = int.Parse(Request.QueryString["ID"]);
                cmsArticleDO ohjArt = new cmsArticleBL().Select(new cmsArticleDO { ArticleID = ArtID });
                string Title = ohjArt.Title;
                Page.Title = Title + " - " + Ultility.PageTitle();
                string description = ohjArt.Description;
                HtmlMeta metaDesc = new HtmlMeta();
                metaDesc.Name = "description";
                metaDesc.Content = description + " - " + new sysConfigBL().Select(new sysConfigDO { ConfigID = 1 }).ConfigValue;
                Page.Header.Controls.Add(metaDesc);

                string Tag = ohjArt.Tags;
                HtmlMeta metaKey = new HtmlMeta();
                metaKey.Name = "key";
                metaKey.Content = Tag;
                Page.Header.Controls.Add(metaKey);

                int articleID = int.Parse(Request.QueryString["ID"]);
                rptArticleDataSource(articleID);
                rptOtherArticleDataSource(articleID);
                if (!IsPostBack)
                {
                    string CurrentUrl = "http://" + Request.Url.Host + Request.RawUrl;
                    hplFacebook.NavigateUrl = hplFacebook.NavigateUrl + CurrentUrl;
                    hplGoogle.NavigateUrl = hplGoogle.NavigateUrl + CurrentUrl;
                    hplTwitter.NavigateUrl = hplTwitter.NavigateUrl + CurrentUrl;

                    //abc.Attributes.Add("src", "//www.facebook.com/plugins/like.php?href=" + CurrentUrl + "&send=false&layout=button_count&width=450&show_faces=false&action=like&colorscheme=light&font&height=21&appId=379138395463852");
                    abc.Attributes.Add("src", "//www.facebook.com/plugins/like.php?href=" + CurrentUrl + "&send=false&layout=button_count&width=450&show_faces=false&action=like&colorscheme=light&font&height=21&appId=379138395463852");
                }
            }
            else
            {
                Page.Title = Ultility.PageTitle();
                HtmlMeta metaDesc = new HtmlMeta();
                metaDesc.Name = "description";
                metaDesc.Content = new sysConfigBL().Select(new sysConfigDO { ConfigID = 1 }).ConfigValue;
                Page.Header.Controls.Add(metaDesc);
            }
        }
        protected void rptArticleDataSource(int articleID)
        {
            rptArticle.DataSource = new cmsArticleBL().SelectByArticleID(articleID);
            rptArticle.DataBind();
        }
        protected void rptOtherArticleDataSource(int articleID)
        {
            int categoryID = new cmsArticleBL().Select(new cmsArticleDO{ArticleID = articleID}).CategoryID;
            rptOtherArticle.DataSource = new cmsArticleBL().SelectByCatNumOld(categoryID, 10, articleID);// new DataView(new cmsArticleBL().SelectByCatNumOld(categoryID, 10, articleID), "ArticleID <> " + articleID, "", DataViewRowState.CurrentRows);
            rptOtherArticle.DataBind();
        }
        protected string FriendlyUrl(string s)
        {
            return Ultility.Change_AV(s);
        }

        public string FriendlyUrl2(string s)
        {
            return Ultility.Change_AV2(s);
        }

        public string CategoryTitle(string CategoryID)
        {
            string CategoryTitle = "";
            CategoryTitle = FriendlyUrl2(new cmsCategoryBL().Select(new cmsCategoryDO { CategoryID = int.Parse(CategoryID) }).Title);
            return CategoryTitle;
        }
    }
}